﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Infra.Utils.ExpressionTree
{
    public class DefaultValueRule : IDefaultValueRule
    {
        private static readonly List<Tuple<Type, object>> _dic;

        static DefaultValueRule ()
        {
            _dic = new List<Tuple<Type, object>>();
            _dic.Add(new Tuple<Type, object>(typeof(byte), 0));
            _dic.Add(new Tuple<Type, object>(typeof(short), 0));
            _dic.Add(new Tuple<Type, object>(typeof(int), 0));
            _dic.Add(new Tuple<Type, object>(typeof(long), 0));
            _dic.Add(new Tuple<Type, object>(typeof(decimal), 0));
            _dic.Add(new Tuple<Type, object>(typeof(double), 0));

            _dic.Add(new Tuple<Type, object>(typeof(string), ""));
            //_dic.Add(new Tuple<Type, object>(typeof(string), null));
            _dic.Add(new Tuple<Type, object>(typeof(bool), false));
        }

        public bool IsDefault(object value)
        {
            bool result = true;

            if (value != null)
            {
                var type = Type.GetType(value.GetType().FullName);

                if (_dic.Any(a => a.Item1 == type && a.Item2.Equals(value) == false))
                    result = false;
            }

            return result;
        }
    }
}
